const path = require('path')
const merge = require('webpack-merge')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const baseWebpackConfig = require('./webpack.config.base')
const webpack = require('webpack')

const vueDir = path.resolve('src')
console.log('vue dir', vueDir)

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

const devWebpackConfig = merge(baseWebpackConfig, {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist/'),
    filename: '[name].js'
  },
  devServer: {
    clientLogLevel: 'warning',
    contentBase: path.resolve(__dirname, './dist'),
    hot: true,
    host: 'localhost',
    port: 8080
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  module: {
    rules: [{
      test: /\.vue$/,
      // include: [path.resolve("src")],
      loader: 'vue-loader',
      exclude: /node_modules/,
      options: {
        esModule: false,
        loaders: [{
          loader: "css-loader",
          options: {
            minimize: false,
            sourceMap: true
          }
        }]
      }
    }]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new HtmlWebPackPlugin({
      // filename: 'index.html',
      template: './src/index.html',
      inject: true
    })
  ]
})



module.exports = new Promise((resolve, reject) => {
  console.log('export', devWebpackConfig)
  resolve(devWebpackConfig)
})

// module.exports = {
//   devServer: {
//     contentBase: path.join(__dirname, 'dist'),
//     compress: true,
//     port: 9000
//   }
// }